using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Markup;
using SettingsView.ViewModel;
using SSettings;

namespace SettingsView
{
	public partial class UCGridColumnEdit : UserControl, IComponentConnector
	{
		public static readonly DependencyProperty RestoreDefaultSelectVisibleProperty = DependencyProperty.Register("RestoreDefaultSelectVisible", typeof(bool), typeof(UCGridColumnEdit), new UIPropertyMetadata(true));

		public static readonly DependencyProperty GridColumnsProperty = DependencyProperty.Register("GridColumns", typeof(GridColumns), typeof(UCGridColumnEdit), new UIPropertyMetadata(null, OnGridColumnsChanged));

		public bool RestoreDefaultSelectVisible
		{
			get
			{
				return (bool)GetValue(RestoreDefaultSelectVisibleProperty);
			}
			set
			{
				SetValue(RestoreDefaultSelectVisibleProperty, value);
			}
		}

		public GridColumns GridColumns
		{
			get
			{
				return (GridColumns)GetValue(GridColumnsProperty);
			}
			set
			{
				SetValue(GridColumnsProperty, value);
			}
		}

		private static void OnGridColumnsChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCGridColumnEdit uCGridColumnEdit = sender as UCGridColumnEdit;
			if (uCGridColumnEdit != null && uCGridColumnEdit.GridColumns != null)
			{
				GridColumnEditViewMode dataContext = new GridColumnEditViewMode(uCGridColumnEdit.GridColumns);
				uCGridColumnEdit.checkNotDiplayNullColumn.SetBinding(ToggleButton.IsCheckedProperty, new Binding("NotDisplayNullColumn")
				{
					Source = uCGridColumnEdit.GridColumns,
					Mode = BindingMode.TwoWay,
					UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
				});
				uCGridColumnEdit.DataContext = dataContext;
			}
		}

		public UCGridColumnEdit()
		{
			InitializeComponent();
		}
	}
}
